package com.mison.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.sql.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mison.core.Action;
import com.mison.core.FrameworkFather;
import com.mison.core.Result;
import com.mison.dao.MisonFeedbackDao;
import com.mison.model.MisonFeedback;
import com.mison.utils.Page;

public class WumjAction extends FrameworkFather {
	
	private Page<MisonFeedback> page = new Page<MisonFeedback>(1);
	
	private String id;
	
	
	MisonFeedback m = new MisonFeedback();
	 
	private Date time;

	public Result execute(HttpServletRequest request, HttpServletResponse response, Action action) {
		
		MisonFeedbackDao dao = new MisonFeedbackDao();
		
		page.setList(dao.getList(page));
		
		int total = dao.getCount();

		page.setTotalCount(total);
		
		page.setMaxPage((int)Math.ceil((double)total/page.getPerPage()));
		
		return action.getResult("wmj");
	}
	
    public Result delete(HttpServletRequest request, HttpServletResponse response, Action action) {
		
		MisonFeedbackDao dao = new MisonFeedbackDao();
		
		dao.delete(Integer.parseInt(id));
	
		return action.getResult("delete");
	}
    
    public Result updateClass(HttpServletRequest request, HttpServletResponse response, Action action) {
		
		MisonFeedbackDao dao = new MisonFeedbackDao();
		
		m = dao.updateClass(Integer.parseInt(id));
	
		return action.getResult("updateClass");
	}
	
    public Result update(HttpServletRequest request, HttpServletResponse response, Action action) {
		
		MisonFeedbackDao dao = new MisonFeedbackDao();	
		m.setTime(time);
		dao.update(m);
	
		return action.getResult("update");
	}

	public Page<MisonFeedback> getPage() {
		return page;
	}

	public void setPage(Page<MisonFeedback> page) {
		this.page = page;
	}
	
	public void setCurrPage(String currPage){
		page.setCurrPage(Integer.parseInt(currPage));
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public Date getTime() {
		return time;
	}

	public void setTime(String time) {
		
		
		try {
			SimpleDateFormat   timeformat=new   SimpleDateFormat( "yyyy-mm-dd "); 
			java.util.Date   rs = timeformat.parse(time);
			Date d1 = new   java.sql.Date(rs.getTime());
			this.time = d1;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 

		
	}

	public MisonFeedback getM() {
		return m;
	}

	public void setM(MisonFeedback m) {
		this.m = m;
	}



	

	
	
}
